package dataStructure.study.sort;

import java.util.jar.JarEntry;

/**
 * Author: shangsf
 * Date: 2021/4/6 23:07
 * Description:选择排序，时间复杂度O(n^2)
 */
public class SelectionSort {
    public static void sort(int[] array) {
        if (array == null || array.length == 1) {
            return;
        }
        int n = array.length;
        for(int i=0;i<n-1;i++){
            int index=i;
            for(int j=i+1;j<n;j++){
                if(array[j]<array[index]){
                    index=j;
                }
            }
            if(index!=i){
                int tmp=array[i];
                array[i]=array[index];
                array[index]=tmp;
            }
        }
    }
}
